package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "管理端-店铺操作相关接口")
public class ShopController {

    public static final String KEY = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;



    @PutMapping("/{status}")
    @ApiOperation("管理端-设置店铺营业状态")
    public Result<String> setStatus(@PathVariable Integer status){
        //将状态设置到Redis中
        log.info("设置营业状态：{}",status==1? "营业中" : "打烊了");
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("管理端-查询店铺营业状态")
    public Result<Integer> setStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("管理端查看营业状态为：{}",status==1? "营业中" : "打烊了");
        return Result.success(status);
    }

}
